package model_javabean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;

public class Admin_User {
	private int id;
	private String userName;
	private String juese;
	private String phone;
	private String address;
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPhone() {
		return phone;
	}
	public void setPhone(String phone) {
		this.phone = phone;
	}
	public String getJuese() {
		return juese;
	}
	public void setJuese(String juese) {
		this.juese = juese;
	}
	public String getUserName() {
		return userName;
	}
	public void setUserName(String userName) {
		this.userName = userName;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
   public ArrayList<Admin_User> getUser() throws ClassNotFoundException, SQLException{
	    ArrayList<Admin_User> users=new ArrayList<Admin_User>();
	    Class.forName("com.mysql.jdbc.Driver");
		String dbUrl="jdbc:mysql://localhost:3306/mealsystem";
		Connection con=DriverManager.getConnection(dbUrl,"root","root");
		Statement stmt=con.createStatement();
		String sql="select * from user";
		ResultSet rs=stmt.executeQuery(sql);
		while(rs.next()){
			Admin_User u=new Admin_User();
			u.setId(rs.getInt("id"));
			u.setAddress(rs.getString("address"));
			u.setJuese(rs.getString("ident"));
			u.setPhone(rs.getString("telephone"));
			u.setUserName(rs.getString("userName"));
			users.add(u);
			
		}
		rs.close();
		stmt.close();
		con.close();
		return users;
   }
}
